package com.twq.types.typeparam.covariant

/**
 * Created by tangweiqun on 2017/12/6.
 */
trait CustomList[+ItemType] {
  //下界：类型参数必须是ItemType或者是ItemType的父类，ItemType称之为下界
  def ++[OtherItemType >: ItemType](
                                     other: CustomList[OtherItemType]): CustomList[OtherItemType]
}

class EmptyList[ItemType] extends CustomList[ItemType] {
  def ++[OtherItemType >: ItemType](
                                     other: CustomList[OtherItemType]) = other
}


object CustomList {
  def main(args: Array[String]): Unit = {
    val strings = new EmptyList[String]
    val ints = new EmptyList[Int]
    val anys = new EmptyList[Any]
    val anyrefs = new EmptyList[AnyRef]

    strings ++ ints
    strings ++ anys
    strings ++ anyrefs
    strings ++ strings
  }
}